<template>
<div>
  <div class="loader-base" v-if="showLoad"><div class="loader-wrap"></div></div>
  <header-box :title="'我的差旅报销'" :hasArrow="true"></header-box>
  <list-timeRange @changeTimeRange="getTime"></list-timeRange>
  <list-card :listDatas='listDatas' :totalLength='totalLength'
             :url="'/reimbursement/detail'"
             @changePage="getData"></list-card>
</div>
</template>
<script>
import listCard from "@/components/share/listCard.vue";
import listTimeRange from "@/components/share/listTimeRange.vue";
export default {
  components:{
    listCard,
    listTimeRange
  },
  data() {
    return {
      showLoad:false,
      listDatas:[],
      pageIndex:1,
      totalLength:0,
      startdate:'',
      enddate:'',
    };
  },
  watch: {

  },
  computed: {
    userInfo(){
      return localStorage.UserInfo?JSON.parse(localStorage.UserInfo):'';
    }
  },
  created() {
    this.getData();
  },
  methods: {
    getData(){
      this.showLoad = true;
      let data={
        "pagesize": 10,
        "pageindex": this.pageIndex,
        "staffid": this.userInfo.staffid,
        "datastatus": "",
        "startdate": this.startdate,
        "enddate": this.enddate
      };
      let _this = this;
      this.Ajax.post('ExpenseAccountService/MyExpenseAccountQuery',data).then(function(resp) {
        if(resp.code == 'SUCC'){
          let result = JSON.parse(resp.data);
          let todolist = JSON.parse(result.data);
          //列表类型数组重定义
          for(let i in todolist){
            todolist[i].classify = '差旅报销';
          }
          _this.totalLength = result.recordcount;
          _this.listDatas = _this.listDatas.concat(todolist);
          _this.pageIndex++;
          // console.log(_this.listDatas,"差旅列表")
        }else{
          _this.$vux.toast.show({
            type: "warn", //success, warn, cancel, text
            text: resp.message
          });
        }
        _this.showLoad = false;
      });
    },
    //获取时间
    getTime(val1,val2){
      // console.log(val1,val2,"出差时间段")
      if(val1>val2){
        this.$vux.toast.show({
          type: "warn", //success, warn, cancel, text
          text: "开始时间不能大于结束时间"
        });
        return false;
      };
      this.startdate = val1;
      this.enddate = val2;
      this.pageIndex = 1;
      this.listDatas = [];
      this.getData();
    }
  }
};
</script>